package com.google.code.p.slideunlocker;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.AbsoluteLayout.LayoutParams;

public class SlidableButton extends Button{
  private boolean isDragging = false;
  private boolean isAnimating = false;
  private View txt;
  
  public SlidableButton(Context context) {
      super(context);
  }
  
  public SlidableButton(Context context, AttributeSet attrs){
      super(context, attrs);
  }
  
  public void setTxt(View txt) {
    this.txt = txt;
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_DOWN){
      txt.setVisibility(View.INVISIBLE);
      isDragging = true;
    }
    return false;
  }
  
  public void setAnimating(boolean isAnimating) {
    this.isAnimating = isAnimating;
  }
  
  public boolean isAnimating() {
    return isAnimating;
  }
  
  public void setDragging(boolean isDragging) {
    this.isDragging = isDragging;
  }
  public boolean isDragging() {
    return isDragging;
  }
  public void setX(int x){
    if(isDragging && !isAnimating){
      AbsoluteLayout.LayoutParams lp = (LayoutParams)getLayoutParams();
      lp.x = x;
      setLayoutParams(lp);
    }
  }
  
}